package projectx.core.base;

public class ProjectXException extends Exception {
	private final ProjectXMessage _msg;
	private final ProjectXMessage _cause;

	public ProjectXException(String key) {

		this(key, null);
	}

	public ProjectXException(String key, Object value0) {

		this(key, new Object[] { value0 });
	}

	public ProjectXException(String key, Object value0, Object value1) {

		this(key, new Object[] { value0, value1 });
	}

	public ProjectXException(String key, Object value0, Object value1,
			Object value2) {

		this(key, new Object[] { value0, value1, value2 });
	}

	public ProjectXException(String key, Object[] values) {

		this(new ProjectXMessage(key, values));
	}

	public ProjectXException(ProjectXMessage msg) {

		super(msg.toString());

		_msg = msg;
		_cause = null;
	}

	public ProjectXException(ProjectXMessage msg, ProjectXMessage cause) {

		super(msg.toString());

		_msg = msg;
		_cause = cause;
	}

	public ProjectXException(ProjectXMessage msg, ProjectXMessage cause,
			Throwable t) {

		super(msg.toString(), t);

		_msg = msg;
		_cause = cause;
	}

	public ProjectXException(ProjectXMessage msg, Throwable t) {

		this(msg, null, t);
	}

	public ProjectXMessage getPolarisMessage() {
		return _msg;
	}

	public ProjectXMessage getCauseMessage() {
		return _cause;
	}

	public String getMessage() {

		return getMessage(true);
	}

	public String getMessage(boolean displayKey) {

		return _msg.getMessage(displayKey);
	}

	public String toString() {

		return getMessage()
				+ ((_cause == null) ? "" : " RootCause - " + _cause);
	}
}
